package com.axzhengxin.platform.homePage.controller;

import com.axzhengxin.platform.homePage.domain.MonthResult;
import com.axzhengxin.platform.homePage.domain.SearchParams;
import com.axzhengxin.platform.homePage.domain.StatisticData;
import com.axzhengxin.platform.homePage.domain.TaskAgent;
import com.axzhengxin.platform.homePage.service.IHomePageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author AHZJ0005
 * @Date 2021/3/1-18:21
 * 首页
 **/
@RestController
@RequestMapping("/homePage")
public class HomePageController extends BaseController {


    @Autowired
    private IHomePageService homePageService;

    /**
     * 查询近六天申请统计、授信统计
     */
    @RequestMapping("/statistic")
    public List<StatisticData> statistic(Integer flag) {
        List<StatisticData> auditingStatistic;
        SearchParams searchParams = new SearchParams();
        if (flag == 1) {
            //申请统计
            searchParams.setFlag(1);
            auditingStatistic = homePageService.getAuditingStatistic(searchParams);
        } else {
            //授信统计
            searchParams.setFlag(2);
            auditingStatistic = homePageService.getApproveStatistic(searchParams);
        }
        return auditingStatistic;
    }

    /**
     * 查询代办任务
     */
    @RequestMapping("/taskAgent")
    public TaskAgent taskAgent() {
        //待审核订单
        String userId = String.valueOf(SecurityUtils.getLoginUser().getUser().getUserId());
        SearchParams searchParams1 = new SearchParams();
        searchParams1.setAnotherStatus(1010);
        searchParams1.setStatus(10);
        searchParams1.setType("APPLY");
        searchParams1.setUserId(userId);
        int auditingCount = homePageService.getTaskAgentCount(searchParams1);
        //待授信订单
        SearchParams searchParams2 = new SearchParams();
        searchParams2.setStatus(1010);
        searchParams2.setType("APPROVE");
        searchParams2.setUserId(userId);
        int approveCount = homePageService.getTaskAgentCount(searchParams2);
        //待放款订单
        SearchParams searchParams3 = new SearchParams();
        searchParams3.setStatus(1010);
        searchParams3.setType("LOAN");
        searchParams3.setUserId(userId);
        int loanCount = homePageService.getTaskAgentCount(searchParams3);

        //预警信号
        int warnCount=homePageService.getWarnCount(new SearchParams());
        TaskAgent taskAgent = new TaskAgent();
        taskAgent.setApproveCount(approveCount);
        taskAgent.setAuditingCount(auditingCount);
        taskAgent.setLoanCount(loanCount);
        taskAgent.setWarnCount(warnCount);
        return taskAgent;
    }

    /**
     * 获取首页月度成果
     *
     * @return 集合
     */
    @RequestMapping("/monthResult")
    public List<MonthResult> monthResults(MonthResult monthResult) {
        return homePageService.monthResults(monthResult);
    }

}
